package cn.lyf.listener;

import org.springframework.beans.factory.SmartInitializingSingleton;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

/*
ContextRefreshedEvent: 容器刷新完成会发布
ContextClosedEvent: 关闭容器会发布该事件
发布
applicationContext.publishEvent(new ApplicationEvent("消息"))
   1）refresh
   2）finishRefresh
   3) publishEvent
      1)getApplicationEventMulticaster() 获取多播地址
      2)multicastEvent 派发事件
          如果异步就getTaskExecutor()异步执行

   =========
  @EventListener(classes={ApplicationEvent.class})
 使用EventListenerMethodProcessor处理器来解析 实现了 【SmartInitializingSingleton】

 SmartInitializingSingleton
    1）创建好单实例bean 后判断是否是 SmartInitializingSingleton
    2） 调用afterSingletonsInstantiated

 */
@Component
public class MyApplicationListener implements ApplicationListener<ApplicationEvent> {

    @Override
    public void onApplicationEvent(ApplicationEvent event) {
        System.out.println("收到事件: "+event);
    }
}
